/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo.classes;

import java.util.Scanner;
import java.util.zip.DataFormatException;
import javax.swing.text.BadLocationException;

/**
 *
 * @author VANDH
 */
public class JPI {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
//        Book book1 = new Book(); // publisher của class Book
//        Book.publisher = "VANDH";
//        Book book2 = new Book();
//        Book.publisher = "SINH1";   // publisher của class Book
        //System.out.println(Book.getPublisher());
        //demoBook();

//        try {
//            System.out.println(div1(1, 0)); // chỗ đang gọi nhận được object ArithmeticException
//            System.out.println("Đã insert thành công");
//        } catch (Exception ex) {
//            System.out.println("Có lỗi, không chia được");
//        }
//
//        System.out.println("Đã hết hàm main");

        Scanner keyboard = new Scanner(System.in);
        String s = keyboard.nextLine();
        System.out.println(keyboard.nextInt());
        System.out.println(s);
    }

    public static int div1(int a, int b) throws DataFormatException {
        System.out.println("div1");
        try {
            //IndexOutOfBoundsException
            return div2(a, b); // chỗ đang gọi nhận được object ArithmeticException("/ by zero")

        } catch (ArithmeticException ex) {
            throw new DataFormatException();
        } catch (IndexOutOfBoundsException ex) {
            //
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            return -1;
        } finally {
            System.out.println("I died");
        }

        return 0;
    }

    public static int div2(int a, int b) {
        System.out.println("div2");
        return a / b; // JVM throw new java.lang.ArithmeticException("/ by zero")
    }

    public static void demoBook() {
        Book get = new Book();
        get.setIsbn();
        get.getIsbn();
        get.cach();
        get.addBook();
        get.displayBooks();
    }

    public static void demoStudent() {
        Student first =
                new Student((float) 4.5, (float) 5.5, (float) 6.5);

        // first -> object of Student
        // nếu first = new Student() -> cũng gọi first là instance of Student
        // new Student() -> instance of Student
        first.fullName = "Nguyen Van A";
        first.id = "MS001";

        Student second = new Student();
        second.subjectOne = (float) 1;
        second.subjectTwo = (float) 2;
        second.subjectThree = (float) 3;

        System.out.printf("Total : %f, Average : %f\n", first.total(), first.average());
        System.out.printf("Total : %f, Average : %f\n", second.total(), second.average());
    }
}